<template>
  <div class="album-container">
    <!-- 添加滚动指示器 -->
    <div class="scroll-indicator" :style="{ width: scrollProgress + '%' }"></div>

    <!-- 添加动态页头 -->
    <header class="album-header" :class="{ 'header-scrolled': isHeaderScrolled }">
      <div class="header-content">
        <h1 class="title" :class="{ 'title-small': isHeaderScrolled }">
          <span class="icon">📸</span>
          <span class="text">我的相册</span>
        </h1>
        <p class="subtitle" v-show="!isHeaderScrolled">珍藏美好时刻</p>
        <div class="header-decoration" v-show="!isHeaderScrolled">
          <span class="line"></span>
          <span class="dot"></span>
          <span class="line"></span>
        </div>
        <!-- 添加滚动信息 -->
        <div class="scroll-info" v-show="isHeaderScrolled">
          <span class="photo-count">{{ allPhotos.length }} 张照片</span>
          <span class="divider">|</span>
          <span class="scroll-position">已浏览 {{ Math.round(scrollProgress) }}%</span>
        </div>
      </div>
    </header>

    <!-- 返回按钮 -->
    <div class="back-btn" @click="goBack">
      <span class="back-icon">←</span>
      <span class="back-text">主页</span>
    </div>

    <!-- 替换返回顶部按钮 -->
    <div class="lamp-button" 
         v-show="showBackToTop"
         @click="scrollToTop">
      <div class="lamp">
        <div class="bulb">
          <div class="light"></div>
        </div>
        <div class="string" :style="{ height: ropeLength + 'px' }"></div>
      </div>
    </div>

    <!-- 相册内容 -->
    <div class="album-content">
      <div v-for="(photo, index) in visiblePhotos" 
           :key="index" 
           class="photo-card"
           :ref="el => { if (el) photoRefs[index] = el }"
           @click="showPhoto(index)">
        <div class="photo-wrapper">
          <img :src="photo.url" 
               :alt="photo.description"
               @load="onImageLoad(index)"
               v-lazy>
          <div class="photo-info">
            <div class="info-header">
              <span class="date">{{ photo.date }}</span>
              <span class="size">{{ photo.size }}</span>
            </div>
            <h3 class="title">{{ photo.title }}</h3>
            <p class="description">{{ photo.description }}</p>
            <div class="tags">
              <span v-for="(tag, tagIndex) in photo.tags" 
                    :key="tagIndex" 
                    class="tag">{{ tag }}</span>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 添加加载指示器 -->
      <div v-if="isLoading" class="loading-indicator">
        <div class="spinner"></div>
        <span>加载更多照片...</span>
      </div>

      <!-- 添加底部提示 -->
      <div v-if="!isLoading && visiblePhotos.length === allPhotos.length" 
           class="end-message"
           :class="{ 'fade-in': showEndMessage }">
        <div class="line"></div>
        <span class="text">
          <span class="icon">🎉</span>
          已经到底啦
        </span>
        <div class="line"></div>
      </div>
    </div>

    <!-- 照片预览模态框 -->
    <transition name="modal">
      <div class="photo-modal" v-if="selectedPhoto !== null" @click.self="closePreview">
        <!-- 导航按钮容器 -->
        <div class="nav-buttons">
          <button class="nav-btn prev" 
                  @click="prevPhoto" 
                  :class="{ disabled: selectedPhoto <= 0 }">
          </button>
          <button class="nav-btn next" 
                  @click="nextPhoto" 
                  :class="{ disabled: selectedPhoto >= allPhotos.length - 1 }">
          </button>
        </div>

        <div class="modal-content">
          <div class="image-container" 
               ref="imageContainer"
               :style="{ transform: `rotate(${rotation}deg) scale(${scale})` }"
               @wheel="handleWheel">
            <img :src="currentPhoto?.url" :alt="currentPhoto?.description">
          </div>

          <!-- 工具栏 -->
          <div class="toolbar">
            <button @click="rotateLeft" title="向左旋转">↺</button>
            <button @click="rotateRight" title="向右旋转">↻</button>
            <button @click="resetTransform" title="重置">⟲</button>
            <button @click="downloadImage" title="下载">⭳</button>
            <button @click="toggleDetails" title="查看详情">ℹ</button>
          </div>

          <!-- 添加详情侧边栏 -->
          <transition name="slide">
            <div class="photo-details" v-if="showDetails">
              <div class="details-header">
                <h3>照片详情</h3>
                <button class="close-details" @click="toggleDetails">×</button>
              </div>
              <div class="details-content">
                <div class="detail-item">
                  <span class="label">标题</span>
                  <span class="value">{{ currentPhoto?.title }}</span>
                </div>
                <div class="detail-item">
                  <span class="label">日期</span>
                  <span class="value">{{ currentPhoto?.date }}</span>
                </div>
                <div class="detail-item">
                  <span class="label">大小</span>
                  <span class="value">{{ currentPhoto?.size }}</span>
                </div>
                <div class="detail-item">
                  <span class="label">类型</span>
                  <span class="value">{{ currentPhoto?.type }}</span>
                </div>
                <div class="detail-item">
                  <span class="label">描述</span>
                  <p class="value description">{{ currentPhoto?.description }}</p>
                </div>
                <div class="detail-item">
                  <span class="label">标签</span>
                  <div class="tags">
                    <span v-for="(tag, index) in currentPhoto?.tags" 
                          :key="index" 
                          class="tag">{{ tag }}</span>
                  </div>
                </div>
              </div>
            </div>
          </transition>

          <!-- 关闭按钮 -->
          <button class="close-btn" @click="closePreview">×</button>
        </div>
      </div>
    </transition>

    <!-- 修改通知组件，添加 transition 包装 -->
    <transition name="notification">
      <div class="notification" v-if="showNotification">
        <div class="notification-content">
          <div class="notification-header">
            <span class="icon">⭳</span>
            <span class="title">下载中...</span>
          </div>
          <div class="progress-bar">
            <div class="progress" :style="{ width: `${downloadProgress}%` }"></div>
          </div>
          <div class="notification-text">{{ notificationText }}</div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

// 生成随机日期
const generateRandomDate = () => {
  const start = new Date('2023-01-01').getTime();
  const end = new Date('2024-03-31').getTime();
  const randomTime = start + Math.random() * (end - start);
  const date = new Date(randomTime);
  return date.toISOString().split('T')[0];
};

// 生成随机大小
const generateRandomSize = () => {
  const size = (Math.random() * 4 + 0.5).toFixed(1); // 0.5MB 到 4.5MB
  return `${size}MB`;
};

// 随机标签池
const tagPool = [
  '生活', '日常', '风景', '美食', '旅行', 
  '节日', '礼物', '纪念', '家庭', '朋友',
  '宠物', '音乐', '运动', '艺术', '时尚',
  '创意', '快乐', '温馨', '浪漫', '自然'
];

// 生成随机标签
const generateRandomTags = () => {
  const numTags = Math.floor(Math.random() * 3) + 1; // 1-3个标签
  const shuffled = [...tagPool].sort(() => 0.5 - Math.random());
  return shuffled.slice(0, numTags);
};

// 描述池
const descriptionPool = [
  '美好的一天', '难忘的时刻', '温馨的记忆',
  '快乐时光', '精彩瞬间', '珍贵回忆',
  '幸福时刻', '美好记忆', '温暖瞬间',
  '欢乐时光', '美好生活', '温馨日常',
  '精彩生活', '美好记录', '幸福日常'
];

// 生成随机描述
const generateRandomDescription = () => {
  return descriptionPool[Math.floor(Math.random() * descriptionPool.length)];
};

// 生成照片数据
const generatePhotos = () => {
  const photos = [];
  for (let i = 2; i <= 30; i++) {
    photos.push({
      url: require(`@/assets/img/${i}.png`),
      date: generateRandomDate(),
      description: generateRandomDescription(),
      height: 0,
      title: `照片${i}`,
      type: 'PNG',
      size: generateRandomSize(),
      tags: generateRandomTags()
    });
  }
  return photos;
};

// 照片数据
const allPhotos = ref([
  {
    url: require('@/assets/img/1.jpeg'),
    date: '2024-03-31',
    description: '好康的',
    height: 0,
    title: '照片1',
    type: 'JPG',
    size: '2.5MB',
    tags: ['生活', '日常']
  },
  ...generatePhotos()
]);

// 状态变量
const selectedPhoto = ref(null);
const rotation = ref(0);
const scale = ref(1);

const isMobile = ref(window.innerWidth <= 768);
const imageContainer = ref(null);
const showBackToTop = ref(false);

// 计算当前照片
const currentPhoto = computed(() => {
  if (selectedPhoto.value === null) return null;
  return allPhotos.value[selectedPhoto.value];
});

// 图片加载处理
const onImageLoad = (index) => {
  if (allPhotos.value[index]) {
    const img = event.target;
    allPhotos.value[index].height = img.naturalHeight;
  }
};

// 导航功能
const goBack = () => router.push('/');
const showPhoto = (index) => selectedPhoto.value = index;
const closePreview = () => {
  selectedPhoto.value = null;
  rotation.value = 0;
  scale.value = 1;
  showDetails.value = false;
};

const prevPhoto = () => {
  if (selectedPhoto.value > 0) {
    selectedPhoto.value--;
    resetTransform();
  }
};

const nextPhoto = () => {
  if (selectedPhoto.value < allPhotos.value.length - 1) {
    selectedPhoto.value++;
    resetTransform();
  }
};

// 图片操作功能
const rotateLeft = () => rotation.value = (rotation.value - 90) % 360;
const rotateRight = () => rotation.value = (rotation.value + 90) % 360;
const resetTransform = () => {
  rotation.value = 0;
  scale.value = 1;
};

// 滚轮缩放
const handleWheel = (e) => {
  e.preventDefault();
  const delta = e.deltaY > 0 ? -0.1 : 0.1;
  scale.value = Math.max(0.5, Math.min(3, scale.value + delta));
};

// 添加下载相关的状态
const showNotification = ref(false);
const downloadProgress = ref(0);
const notificationText = ref('准备下载...');

// 修改下载图片函数
const downloadImage = async () => {
  if (!currentPhoto.value) return;
  
  try {
    showNotification.value = true;
    downloadProgress.value = 0;
    notificationText.value = '准备下载...';

    const response = await fetch(currentPhoto.value.url);
    const reader = response.body.getReader();
    const contentLength = +response.headers.get('Content-Length');

    let receivedLength = 0;
    const chunks = [];

    // 修改 while(true) 为更安全的写法
    let result = await reader.read();
    while (!result.done) {
      const value = result.value;
      chunks.push(value);
      receivedLength += value.length;
      
      // 更新进度
      downloadProgress.value = Math.round((receivedLength / contentLength) * 100);
      notificationText.value = `已下载 ${downloadProgress.value}%`;
      
      // 读取下一块数据
      result = await reader.read();
    }

    // 合并数据
    const blob = new Blob(chunks);
    const url = window.URL.createObjectURL(blob);
    
    // 下载文件
    const a = document.createElement('a');
    a.href = url;
    a.download = currentPhoto.value.title + '.' + currentPhoto.value.type.toLowerCase();
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    window.URL.revokeObjectURL(url);

    // 显示完成消息
    notificationText.value = '下载完成！';
    downloadProgress.value = 100;
    
    // 3秒后关闭通知
    setTimeout(() => {
      showNotification.value = false;
      downloadProgress.value = 0;
    }, 3000);

  } catch (error) {
    console.error('下载失败:', error);
    notificationText.value = '下载失败，请重试';
    
    // 3秒后关闭通知
    setTimeout(() => {
      showNotification.value = false;
    }, 3000);
  }
};

// 返回顶部功能
const scrollToTop = () => {
  window.scrollTo({ top: 0, behavior: 'smooth' });
};

// 添加绳子长度计算
const ropeLength = ref(0);

// 修改滚动处理函数
const handleScroll = () => {
  const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
  const windowHeight = window.innerHeight;
  const documentHeight = document.documentElement.scrollHeight;
  
  // 显示/隐藏返回顶部按钮
  showBackToTop.value = scrollTop > 300;
  
  // 计算绳子长度（最小 30px，最大 150px）
  if (showBackToTop.value) {
    const maxScroll = documentHeight - windowHeight;
    const scrollPercent = scrollTop / maxScroll;
    ropeLength.value = Math.min(150, Math.max(30, scrollPercent * 150));
  }

  // 添加页头状态更新
  isHeaderScrolled.value = window.pageYOffset > 100;

  // 计算滚动进度
  const scrolled = (window.pageYOffset / (documentHeight - windowHeight)) * 100;
  scrollProgress.value = Math.min(Math.max(scrolled, 0), 100);

  // 检查是否滚动到底部
  if (windowHeight + window.pageYOffset >= documentHeight - 200) { // 提前200px开始加载
    if (!isLoading.value && visiblePhotos.value.length < allPhotos.value.length) {
      currentBatch.value++;
      loadMorePhotos();
    }
  }
};

// 添加窗口大小变化监听
const handleResize = () => {
  isMobile.value = window.innerWidth <= 768;
};

// 生命周期钩子
onMounted(() => {
  // 添加窗口大小变化监听
  window.addEventListener('resize', handleResize);
  window.addEventListener('scroll', handleScroll);
});

onUnmounted(() => {
  // 移除窗口大小变化监听
  window.removeEventListener('resize', handleResize);
  window.removeEventListener('scroll', handleScroll);
});

// 添加详情相关状态
const showDetails = ref(false);

// 切换详情显示
const toggleDetails = () => {
  showDetails.value = !showDetails.value;
};

// 添加滚动相关状态
const isHeaderScrolled = ref(false);
const scrollProgress = ref(0);

// 添加懒加载相关状态
const photoRefs = ref([]);
const visiblePhotos = ref([]);
const isLoading = ref(false);
const batchSize = 12; // 每次加载的图片数量
const currentBatch = ref(1);

// 计算当前应该显示的照片
const loadMorePhotos = () => {
  isLoading.value = true;
  
  setTimeout(() => {
    const start = (currentBatch.value - 1) * batchSize;
    const end = currentBatch.value * batchSize;
    const newPhotos = allPhotos.value.slice(start, end);
    
    visiblePhotos.value = [...visiblePhotos.value, ...newPhotos];
    isLoading.value = false;

    // 检查是否加载完所有照片
    if (visiblePhotos.value.length === allPhotos.value.length) {
      // 添加小延迟显示底部提示，让体验更流畅
      setTimeout(() => {
        showEndMessage.value = true;
      }, 300);
    }
  }, 500);
};

// 修改懒加载指令实现
const vLazy = {
  mounted: (el) => {
    // 创建占位图URL
    const placeholder = '';
    
    // 保存原始图片URL
    const originalSrc = el.getAttribute('src');
    // 设置占位图
    el.setAttribute('src', placeholder);
    
    const observer = new IntersectionObserver((entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          // 创建新的Image对象来预加载
          const img = new Image();
          img.onload = () => {
            el.src = originalSrc; // 图片加载完成后再显示
          };
          img.src = originalSrc;
          
          observer.unobserve(el);
        }
      });
    }, {
      rootMargin: '50px 0px', // 提前50px开始加载
      threshold: 0.1
    });
    
    observer.observe(el);
  }
};

// 生命周期钩子
onMounted(() => {
  // 初始加载第一批图片
  loadMorePhotos();
  
  // 添加滚动监听
  window.addEventListener('scroll', handleScroll);
});

onUnmounted(() => {
  window.removeEventListener('scroll', handleScroll);
});

// 添加底部提示状态
const showEndMessage = ref(false);

</script>

<style lang="scss" scoped>

.album-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f6f8fb 0%, #f1f4f9 100%);
  padding: 20px;
  position: relative;

  // 添加滚动指示器样式
  .scroll-indicator {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, #6366f1, #a855f7);
    z-index: 1000;
    transition: width 0.2s ease;
  }

  // 添加动态页头
  .album-header {
    padding: 60px 20px 40px;
    text-align: center;
    background: linear-gradient(180deg, 
      rgba(255, 255, 255, 0.9) 0%,
      rgba(255, 255, 255, 0.7) 100%
    );
    backdrop-filter: blur(10px);
    margin-bottom: 30px;
    border-radius: 0 0 30px 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: all 0.3s ease;

    &.header-scrolled {
      padding: 15px 20px;
      border-radius: 0;
      background: rgba(255, 255, 255, 0.95);
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);

      .header-content {
        .title {
          font-size: 24px;
          margin: 0;

          .icon {
            font-size: 24px;
            animation: none;
          }
        }
      }
    }

    .header-content {
      max-width: 800px;
      margin: 0 auto;

      .title {
        transition: all 0.3s ease;
        
        &.title-small {
          margin: 0;
        }
      }

      .scroll-info {
        font-size: 14px;
        color: #666;
        margin-top: 5px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;

        .divider {
          color: #ddd;
        }

        .scroll-position {
          color: #6366f1;
        }
      }
    }
  }

  // 返回按钮
  .back-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;

    &:hover {
      transform: translateY(-2px);
      background: rgba(255, 255, 255, 0.95);
      box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    }
  }

  // 替换返回顶部按钮
  .lamp-button {
    position: fixed;
    top: 80px;
    right: 40px;
    z-index: 1000;
    cursor: pointer;
    
    .lamp {
      display: flex;
      flex-direction: column;
      align-items: center;
      transform-origin: top center;
      animation: swing 3s ease-in-out infinite;

      .bulb {
        width: 40px;
        height: 40px;
        background: rgba(255, 255, 255, 0.9);
        border-radius: 50%;
        position: relative;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        backdrop-filter: blur(10px);
        transition: all 0.3s ease;

        &::before {
          content: '';
          position: absolute;
          top: -8px;
          left: 50%;
          transform: translateX(-50%);
          width: 16px;
          height: 8px;
          background: #ddd;
          border-radius: 4px 4px 0 0;
        }

        .light {
          position: absolute;
          inset: 6px;
          background: linear-gradient(135deg, #6366f1, #a855f7);
          border-radius: 50%;
          opacity: 0.9;
          animation: glow 2s ease-in-out infinite alternate;
        }
      }

      .string {
        width: 2px;
        background: linear-gradient(
          to bottom,
          #ddd,
          rgba(221, 221, 221, 0.5)
        );
        transition: height 0.3s ease;
        position: relative;

        &::after {
          content: '↑';
          position: absolute;
          top: 100%;
          left: 50%;
          transform: translateX(-50%);
          color: #666;
          font-size: 12px;
          margin-top: 5px;
        }
      }
    }

    &:hover {
      .bulb {
        transform: scale(1.1);
        
        .light {
          opacity: 1;
        }
      }
    }
  }

  // 相册内容
  .album-content {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 25px;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;

    .photo-card {
      background: white;
      border-radius: 15px;
      overflow: hidden;
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
      transition: all 0.3s ease;
      cursor: pointer;

      &:hover {
        transform: translateY(-5px);
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);

        img {
          transform: scale(1.05);
        }
      }

      .photo-wrapper {
        position: relative;

        img {
          width: 100%;
          height: 200px;
          object-fit: cover;
          transition: transform 0.3s ease;
        }

        .photo-info {
          padding: 20px;

          .info-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
            color: #666;
            font-size: 14px;
          }

          .title {
            margin: 0 0 10px;
            font-size: 18px;
            color: #333;
          }

          .description {
            margin: 0 0 15px;
            color: #666;
            font-size: 14px;
            line-height: 1.5;
          }

          .tags {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;

            .tag {
              padding: 6px 12px;
              background: #f5f5f5;
              border-radius: 20px;
              font-size: 12px;
              color: #666;
              transition: all 0.3s ease;

              &:hover {
                background: #eee;
                transform: translateY(-2px);
              }
            }
          }
        }
      }
    }
  }

  // 模态框
  .photo-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;

    // 添加导航按钮容器
    .nav-buttons {
      position: absolute;
      inset: 0;
      pointer-events: none; // 防止按钮容器阻挡点击
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 20px;
    }

    // 修改导航按钮样式
    .nav-btn {
      pointer-events: auto; // 恢复按钮的点击事件
      width: 50px;
      height: 50px;
      border: none;
      border-radius: 50%;
      background: rgba(255, 255, 255, 0.15);
      color: white;
      font-size: 24px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      backdrop-filter: blur(8px);
      transition: all 0.3s ease;

      &:hover {
        background: rgba(255, 255, 255, 0.25);
        transform: scale(1.1);
      }

      &:active {
        transform: scale(0.95);
      }

      // 添加按钮图标
      &.prev::before {
        content: '❮';
      }

      &.next::before {
        content: '❯';
      }

      // 禁用状态
      &.disabled {
        opacity: 0.5;
        cursor: not-allowed;
        pointer-events: none;
      }
    }

    .modal-content {
      position: relative;
      max-width: 90vw;
      max-height: 90vh;
      display: flex;
      align-items: center;
      justify-content: center;

      .image-container {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;

        img {
          max-width: calc(100% - 100px);
          max-height: 80vh;
          object-fit: contain;
          transition: transform 0.3s ease;
        }
      }

      // 添加工具栏样式
      .toolbar {
        position: absolute;
        bottom: 30px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        gap: 12px;
        padding: 12px;
        background: rgba(0, 0, 0, 0.6);
        border-radius: 16px;
        backdrop-filter: blur(10px);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        transition: all 0.3s ease;

        &:hover {
          background: rgba(0, 0, 0, 0.7);
          transform: translateX(-50%) translateY(-2px);
        }

        button {
          width: 44px;
          height: 44px;
          border: none;
          border-radius: 12px;
          background: rgba(255, 255, 255, 0.15);
          color: white;
          font-size: 20px;
          cursor: pointer;
          display: flex;
          align-items: center;
          justify-content: center;
          transition: all 0.3s ease;
          position: relative;

          // 悬浮提示
          &::after {
            content: attr(title);
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%) translateY(-8px);
            background: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 6px 10px;
            border-radius: 6px;
            font-size: 12px;
            white-space: nowrap;
            opacity: 0;
            visibility: hidden;
            transition: all 0.2s ease;
          }

          &:hover {
            background: rgba(255, 255, 255, 0.25);
            transform: translateY(-2px);

            &::after {
              opacity: 1;
              visibility: visible;
              transform: translateX(-50%) translateY(-4px);
            }
          }

          &:active {
            transform: translateY(0);
          }
        }
      }

      // 关闭按钮样式
      .close-btn {
        position: absolute;
        top: 20px;
        right: 20px;
        width: 40px;
        height: 40px;
        border: none;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.15);
        color: white;
        font-size: 24px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        backdrop-filter: blur(8px);
        transition: all 0.3s ease;

        &:hover {
          background: rgba(255, 255, 255, 0.25);
          transform: rotate(90deg);
        }

        &:active {
          transform: rotate(90deg) scale(0.95);
        }
      }
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .album-container {
    padding: 10px;

    .album-content {
      grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
      gap: 15px;
      padding: 10px;
    }

    .back-btn {
      padding: 8px 16px;
      font-size: 14px;
    }

    .back-to-top {
      bottom: 20px;
      right: 20px;
      padding: 12px;
    }

    .photo-modal {
      .nav-buttons {
        padding: 0 10px;
      }

      .nav-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
      }
    }

    .album-header {
      padding: 40px 15px 30px;

      &.header-scrolled {
        padding: 10px 15px;

        .header-content {
          .title {
            font-size: 20px;

            .icon {
              font-size: 20px;
            }
          }
        }
      }

      .scroll-info {
        font-size: 12px;
      }
    }
  }

  .photo-modal {
    .modal-content {
      .toolbar {
        bottom: 20px;
        padding: 10px;
        gap: 8px;

        button {
          width: 38px;
          height: 38px;
          font-size: 18px;
        }
      }

      .close-btn {
        width: 36px;
        height: 36px;
        font-size: 20px;
      }
    }
  }
}

// 动画
.modal-enter-active,
.modal-leave-active {
  transition: opacity 0.3s ease;
}

.modal-enter-from,
.modal-leave-to {
  opacity: 0;
}

// 添加动画
@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

// 修改通知栏样式
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  width: 300px;
  z-index: 2000;
  
  .notification-content {
    .notification-header {
      display: flex;
      align-items: center;
      gap: 10px;
      margin-bottom: 12px;

      .icon {
        font-size: 20px;
        color: #6366f1;
      }

      .title {
        font-size: 16px;
        font-weight: 500;
        color: #333;
      }
    }

    .progress-bar {
      height: 6px;
      background: #f0f0f0;
      border-radius: 3px;
      margin-bottom: 8px;
      overflow: hidden;

      .progress {
        height: 100%;
        background: linear-gradient(90deg, #6366f1, #a855f7);
        border-radius: 3px;
        transition: width 0.3s ease;
      }
    }

    .notification-text {
      font-size: 14px;
      color: #666;
    }
  }
}

// 添加进场退场动画
.notification-enter-active,
.notification-leave-active {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.notification-enter-from,
.notification-leave-to {
  opacity: 0;
  transform: translateX(100%);
}

.notification-enter-to,
.notification-leave-from {
  opacity: 1;
  transform: translateX(0);
}

// 修改移动端响应式样式和动画
@media (max-width: 768px) {
  .notification {
    width: calc(100% - 140px);
    max-height: 80px;
    top: 10px;
    right: 20px;
  }

  // 移动端特有的进场退场动画
  .notification-enter-from,
  .notification-leave-to {
    opacity: 0;
    transform: translateY(100%);
  }

  .notification-enter-to,
  .notification-leave-from {
    opacity: 1;
    transform: translateY(0);
  }
}

// 添加弹性动画
@keyframes notification-bounce {
  0% {
    transform: scale(0.95);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

.notification-enter-active {
  animation: notification-bounce 0.3s ease-out;
}

// 添加详情侧边栏样式
.photo-details {
  position: absolute;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(20px);
  color: white;
  padding: 20px;
  overflow-y: auto;

  .details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);

    h3 {
      margin: 0;
      font-size: 18px;
      font-weight: 500;
    }

    .close-details {
      background: none;
      border: none;
      color: white;
      font-size: 24px;
      cursor: pointer;
      padding: 4px;
      transition: all 0.3s ease;

      &:hover {
        transform: rotate(90deg);
      }
    }
  }

  .details-content {
    .detail-item {
      margin-bottom: 16px;

      .label {
        display: block;
        font-size: 12px;
        color: rgba(255, 255, 255, 0.6);
        margin-bottom: 4px;
      }

      .value {
        font-size: 14px;
        color: white;

        &.description {
          line-height: 1.5;
        }
      }

      .tags {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;

        .tag {
          padding: 4px 8px;
          background: rgba(255, 255, 255, 0.1);
          border-radius: 4px;
          font-size: 12px;
        }
      }
    }
  }
}

// 添加侧边栏动画
.slide-enter-active,
.slide-leave-active {
  transition: transform 0.3s ease;
}

.slide-enter-from,
.slide-leave-to {
  transform: translateX(100%);
}

// 响应式适配
@media (max-width: 768px) {
  .photo-details {
    width: 100%;
    height: 50%;
    top: auto;
    bottom: 0;
  }

  .slide-enter-from,
  .slide-leave-to {
    transform: translateY(100%);
  }
}

.photo-modal {
  .modal-content {
    .image-container {
      img {
        max-width: calc(100% - 80px);
        max-height: calc(100vh - 200px);
        object-fit: contain;
      }
    }
  }

  .nav-buttons {
    z-index: 10;
    
    .nav-btn {
      position: relative;
      z-index: 11;
    }
  }
}

@media (max-width: 768px) {
  .photo-modal {
    .modal-content {
      display: flex;
      flex-direction: column;
      height: 100vh;
      width: 100vw;
      position: relative;

      .image-container {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 40px;

        img {
          max-width: calc(100% - 80px);
          max-height: calc(100vh - 200px);
        }
      }

      .toolbar {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 12;
      }
    }

    .nav-buttons {
      position: fixed;
      inset: 0;
      padding: 0 10px;
      
      .nav-btn {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        width: 36px;
        height: 36px;
        background: rgba(255, 255, 255, 0.2);
        
        &.prev {
          left: 10px;
        }
        
        &.next {
          right: 10px;
        }
      }
    }

    .photo-details {
      position: fixed;
      width: 100%;
      height: 70vh;
      top: auto;
      bottom: 0;
      border-radius: 20px 20px 0 0;
      padding: 20px;
      z-index: 15;
      box-sizing: border-box  ;
      display: flex;
      flex-direction: column;

      &::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
      }

      .details-header {
        margin-top: 10px;
        padding-bottom: 15px;
        flex-shrink: 0;
      }

      .details-content {
        flex: 1;
        overflow-y: auto;
        padding: 0 5px 20px 0;
        margin-bottom: env(safe-area-inset-bottom);

        .detail-item {
          margin-bottom: 20px;

          .label {
            font-size: 13px;
            margin-bottom: 6px;
          }

          .value {
            font-size: 15px;
            line-height: 1.6;

            &.description {
              margin-top: 4px;
              white-space: pre-wrap;
            }
          }

          .tags {
            margin-top: 8px;
            gap: 10px;

            .tag {
              padding: 6px 12px;
              font-size: 13px;
            }
          }
        }

        &::-webkit-scrollbar {
          width: 4px;
        }

        &::-webkit-scrollbar-track {
          background: rgba(255, 255, 255, 0.1);
          border-radius: 2px;
        }

        &::-webkit-scrollbar-thumb {
          background: rgba(255, 255, 255, 0.3);
          border-radius: 2px;
        }

        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, 0.3) rgba(255, 255, 255, 0.1);
      }
    }

    .toolbar {
      bottom: calc(70vh + 10px) !important;
      z-index: 16 !important;
    }

    .close-btn {
      z-index: 20;
    }
  }
}

// 适配 iPhone 底部安全区域
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .photo-details {
      padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
  }
}

// 添加加载指示器样式
.loading-indicator {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  color: #666;
  
  .spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #6366f1;
    border-radius: 50%;
    margin-bottom: 10px;
    animation: spin 1s linear infinite;
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

// 添加图片加载动画
.photo-card {
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.5s ease forwards;
  
  @for $i from 1 through 12 {
    &:nth-child(#{$i}) {
      animation-delay: #{$i * 0.1}s;
    }
  }
}

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

// 优化图片加载过渡效果
.photo-wrapper {
  img {
    transition: opacity 0.3s ease;
    
    &[src^="data:"] {
      opacity: 0.5;
      filter: blur(5px);
    }
  }
}

// 添加底部提示样式
.end-message {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px 20px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.5s ease;

  &.fade-in {
    opacity: 1;
    transform: translateY(0);
  }

  .line {
    flex: 1;
    max-width: 100px;
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent,
      rgba(0, 0, 0, 0.1) 50%,
      transparent
    );
  }

  .text {
    color: #666;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;

    .icon {
      font-size: 18px;
      animation: bounce 2s infinite;
    }
  }
}

// 添加图标动画
@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-3px);
  }
  60% {
    transform: translateY(-2px);
  }
}

// 响应式适配
@media (max-width: 768px) {
  .end-message {
    padding: 30px 15px;
    gap: 15px;

    .line {
      max-width: 60px;
    }

    .text {
      font-size: 13px;

      .icon {
        font-size: 16px;
      }
    }
  }
}

// 添加动画
@keyframes swing {
  0%, 100% {
    transform: rotate(-2deg);
  }
  50% {
    transform: rotate(2deg);
  }
}

@keyframes glow {
  from {
    filter: brightness(0.8) blur(0px);
  }
  to {
    filter: brightness(1.2) blur(3px);
  }
}

// 响应式适配
@media (max-width: 768px) {
  .lamp-button {
    bottom: 30px;
    right: 20px;

    .lamp {
      .bulb {
        width: 36px;
        height: 36px;

        &::before {
          width: 14px;
          height: 7px;
          top: -7px;
        }
      }

      .string {
        width: 1.5px;
      }
    }
  }
}
</style>

